<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>取消请求</title>
</head>
<body>
<button class="send">点击发送</button>
<button class="cancel">点击取消</button>
<script>
  var send = document.querySelector('.send');
  var cancel = document.querySelector('.cancel');
  var xhr = new XMLHttpRequest();
  send.onclick = function () {
    xhr.open('GET','http://localhost:8000/delay');
    xhr.send();
  }
  cancel.onclick = function () {
    //取消发送
    xhr.abort();
  }
</script>
</body>
</html>